﻿import QtQuick 2.15
import QtQuick.Controls 2.15

/*
  拉手定位界面
*/

Item {
    id:backGround
    width: screenWidth
    height: 1600

    Rectangle{
        anchors.fill: backGround
        color: "#00bfff"
        border.width: 5
        border.color: "#F0F8FF"
    }

    onVisibleChanged: {
        if(visible === true)
        {
            Cpp_Connect.pageNumber = 7
        }
    }


    Rectangle{
        anchors.top: backGround.top
        anchors.horizontalCenter: backGround.horizontalCenter
        color: "#00BFFF"
        border.width: 5
        border.color: "#F0F8FF"
        width: backGround.width
        height: 150

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 30
            anchors.verticalCenter: parent.verticalCenter
            font.bold: true
            font.pixelSize: 30
            text: qsTr("当前位置")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 180
            anchors.verticalCenter: parent.verticalCenter
            width: 200
            height: 100
            radius: 10
            color: "black"
            border.width: 1
            border.color: "#F0F8FF"

            Text{       // 当前位置显示
                id:currentLocation_Text
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                color: "aqua"
                visible: true
                text: Cpp_Connect.currentLocation
            }
        }
    }

    Rectangle{
        anchors.top: backGround.top
        anchors.topMargin: 145
        anchors.horizontalCenter: backGround.horizontalCenter
        color: "#00BFFF"
        border.width: 5
        border.color: "#F0F8FF"
        width: backGround.width
        height: 150

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 30
            anchors.verticalCenter: parent.verticalCenter
            font.bold: true
            font.pixelSize: 30
            text: qsTr("把手位置")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 180
            anchors.verticalCenter: parent.verticalCenter
            width: 200
            height: 100
            radius: 10
            border.width: 1
            border.color: "#F0F8FF"

            Text{
                id:bs_Location_Text
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                visible: true
                text: Cpp_Connect.LS_Location
            }

            TextInput{      // 把手位置输入框
                id:bs_Location_Input
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                font.italic: true
                maximumLength: 10
                visible: false

                onEditingFinished: {
                    Cpp_Connect.write_modbus_rtu_Hold_F("282",bs_Location_Input.text)
                    bs_Location_Text.visible = true
                    bs_Location_Input.visible = false
                }
            }

            MouseArea{
                anchors.fill: parent

                onClicked: {
                    bs_Location_Input.forceActiveFocus()
                    bs_Location_Input.text = bs_Location_Text.text
                    bs_Location_Text.visible = false
                    bs_Location_Input.visible = true
                    bs_Location_Input.selectAll()
                }
            }
        }


        Text{
            anchors.left: parent.left
            anchors.leftMargin: 470
            anchors.verticalCenter: parent.verticalCenter
            font.bold: true
            font.pixelSize: 30
            text: qsTr("把手位置补偿")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 690
            anchors.verticalCenter: parent.verticalCenter
            width: 200
            height: 100
            radius: 10
            border.width: 1
            border.color: "#F0F8FF"

            Text{
                id:bs_LocationCompensate_Text
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                visible: true
                text: Cpp_Connect.LS_LocationCompensate
            }

            TextInput{      // 把手位置补偿输入框
                id:bs_LocationCompensate_Input
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                font.italic: true
                maximumLength: 10
                visible: false

                onEditingFinished: {
                    Cpp_Connect.write_modbus_rtu_Hold_F("378",bs_LocationCompensate_Input.text)
                    bs_LocationCompensate_Text.visible = true
                    bs_LocationCompensate_Input.visible = false
                }
            }

            MouseArea{
                anchors.fill: parent

                onClicked: {
                    bs_LocationCompensate_Input.forceActiveFocus()
                    bs_LocationCompensate_Input.text = bs_LocationCompensate_Text.text
                    bs_LocationCompensate_Text.visible = false
                    bs_LocationCompensate_Input.visible = true
                    bs_LocationCompensate_Input.selectAll()
                }
            }
        }

    }

    Rectangle{
        anchors.top: backGround.top
        anchors.topMargin: 290
        anchors.horizontalCenter: backGround.horizontalCenter
        color: "#00BFFF"
        border.width: 5
        border.color: "#F0F8FF"
        width: backGround.width
        height: 150

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 30
            anchors.verticalCenter: parent.verticalCenter
            font.bold: true
            font.pixelSize: 30
            text: qsTr("把手宽度")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 180
            anchors.verticalCenter: parent.verticalCenter
            width: 200
            height: 100
            radius: 10
            border.width: 1
            border.color: "#F0F8FF"

            Text{
                id: bs_Width_Text
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                visible: true
                text: Cpp_Connect.LS_Width
            }

            TextInput{      // 把手宽度输入框
                id: bs_Width_Input
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                font.italic: true
                maximumLength: 10
                visible: false

                onEditingFinished: {
                    Cpp_Connect.write_modbus_rtu_Hold_F("284",bs_Width_Input.text)
                    bs_Width_Text.visible = true
                    bs_Width_Input.visible = false
                }
            }

            MouseArea{
                anchors.fill: parent

                onClicked: {
                    bs_Width_Input.forceActiveFocus()
                    bs_Width_Input.text = bs_Width_Text.text
                    bs_Width_Text.visible = false
                    bs_Width_Input.visible = true
                    bs_Width_Input.selectAll()
                }
            }
        }

    }


    Rectangle{
        anchors.top: backGround.top
        anchors.topMargin: 435
        anchors.horizontalCenter: backGround.horizontalCenter
        color: "#00BFFF"
        border.width: 5
        border.color: "#F0F8FF"
        width: backGround.width
        height: 150

        Rectangle{      // 左压料按钮
            width: 220
            height: 100
            radius: 10
            color: "#006cee"
            border.width: 1
            border.color: "#F0F8FF"
            anchors.verticalCenter: parent.verticalCenter
            anchors.left: parent.left
            anchors.leftMargin: 30

            Text{
                anchors.centerIn: parent
                font.pixelSize: 40
                font.bold: true
                text:qsTr("左压料")
            }

            MouseArea{
                anchors.fill: parent

                onPressed: {
                    parent.forceActiveFocus()
                    parent.color = "#ff3606"
                    Cpp_Connect.write_modbus_rtu_Coils("19","1");
                }

                onReleased: {
                    parent.color = "#006cee"
                    Cpp_Connect.write_modbus_rtu_Coils("19","0");
                }
            }
        }

        Rectangle{      // 开始定位
            width: 220
            height: 100
            radius: 10
            color: "#006cee"
            border.width: 1
            border.color: "#F0F8FF"
            anchors.verticalCenter: parent.verticalCenter
            anchors.left: parent.left
            anchors.leftMargin: 300

            Text{
                anchors.centerIn: parent
                font.pixelSize: 40
                font.bold: true
                text:qsTr("开始定位")
            }

            MouseArea{
                anchors.fill: parent

                onPressed: {
                    parent.forceActiveFocus()
                    parent.color = "#ff3606"
                    Cpp_Connect.write_modbus_rtu_Coils("24","1");
                }

                onReleased: {
                    parent.color = "#006cee"
                    Cpp_Connect.write_modbus_rtu_Coils("24","0");
                }
            }
        }





    }


}
